/*
 * @(#)MaintWorkflowStepRoutineAction.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.workflow.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.ErrorConstant;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.web.AbstractActionForm;

/**
 * MaintWorkflowStepRoutineForm.java
 * @author      Tony Chen
 * @company     DCIVision Limited
 * @creation date   25/08/2004
 * @version     $Revision: 1.3 $
 */


public class MaintWorkflowStepRoutineAction extends com.dcivision.framework.web.AbstractMaintAction {

  public static final String REVISION = "$Revision: 1.3 $";

  
  /** Creates a new instance of MaintMultipleFileUploadAction */
  public MaintWorkflowStepRoutineAction() {
    super();
  }

  /** getFunctionCode
   *
   * Abstract function which sub-class should implement to return the corresponding
   * function code.
   *
   * @return   The function code
   */
  public String getFunctionCode() {
    return SystemFunctionConstant.WORKFLOW_TASK;
  }

  /** getMajorDAOClassName
   *
   * Abstract function which sub-class should implement to return the corresponding
   * major DAO class name used in this class.
   *
   * @return   The DAO class name
   */
  public String getMajorDAOClassName() {
    return "com.dcivision.workflow.dao.WorkflowStepDAObject";
  }

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException {
    AbstractActionForm maintForm = (AbstractActionForm)form;

    String opMode = (maintForm != null) ? maintForm.getOpMode() : request.getParameter("opMode"); //maintForm.getOpMode();
    String navMode = (maintForm != null) ? maintForm.getNavMode() : request.getParameter("navMode"); //maintForm.getNavMode();

    if (GlobalConstant.OP_MODE_REFRESH.equals(opMode)) {
      // Set the function code for current action.
      ActionForward forward = this.retrieveFunctionCode(request, response, mapping);
      if (forward != null) {
        return forward;
      }
      refreshFormData(mapping, maintForm, request, response);
      return mapping.findForward(GlobalConstant.NAV_MODE_REFRESH);
    } else {
      return super.execute(mapping, form, request, response);
    }
  }

  public void refreshFormData(ActionMapping mapping, AbstractActionForm form, HttpServletRequest request, HttpServletResponse response) throws
    ApplicationException {
    List resultList = new ArrayList();

    try {
      SessionContainer sessionContainer = this.getSessionContainer(request);
      MaintWorkflowStepRoutineForm wfStepRoutineForm = (MaintWorkflowStepRoutineForm)form;
      int listSize = 0;
      int intNewField = 0;
      String routeListValue = "";
      try {
        listSize = TextUtility.parseInteger(request.getParameter("listSize"));
        intNewField = TextUtility.parseInteger(request.getParameter("newField"));
        routeListValue = request.getParameter("routeListValue");
      } catch (Exception e) {
        throw new ApplicationException(ErrorConstant.COMMON_FATAL_ERROR, e);
      }

      int sum = 0;
      sum = listSize + intNewField; 

      request.setAttribute("listSize", new Integer(listSize));
      request.setAttribute("newFieldsSize", new Integer(sum));
      request.setAttribute("newField", new Integer(intNewField));
      request.setAttribute("routeListValue",routeListValue);
    } catch (ApplicationException appEx) {
      throw appEx;
    } catch (Exception e) {
      log.error(e, e);
      throw new ApplicationException(ErrorConstant.COMMON_FATAL_ERROR, e);
    } finally {
    }
  }



  
  
  
}
